import redis
import json

class RedisClient:
    def __init__(self, host='localhost', port=6379, db=0):
        self.client = redis.Redis(host=host, port=port, db=db)
    
    def put(self, key, value):
        if isinstance(value, dict):
            value = json.dumps(value)
        self.client.set(key, value)
    
    def get(self, key):
        value = self.client.get(key)
        try:
            return json.loads(value)
        except (TypeError, json.JSONDecodeError):
            return value
    
    def delete(self, key):
        self.client.delete(key)
    
    def get_keys(self, pattern='*'):
        return self.client.keys(pattern)

    def get_prefix(self, prefix):
        keys = self.get_keys(f'{prefix}*')
        return {key.decode('utf-8'): self.get(key) for key in keys}
